/** 
  *https://leetcode.cn/problems/minimum-time-to-complete-trips/submissions/567019885/
 * 12187. 完成旅途的最少时间
 * medium,  2024.9.20
 * 二分搜索
*/


class Solution {
public:
    long long minimumTime(vector<int>& time, long long totalTrips) {
        long long l=0, r=1e15;
        while(l<r) {
            long long mid=l+(r-l)/2;
            long long res=0;
            for(auto t:time) {
                res+=mid/t;
                if(res>=totalTrips) break;
            }
            if(res>=totalTrips) {
                r= mid;
            }
            else {
                l=mid+1;
            }
        }
        return l;
    }
};